#!/usr/bin/python
#-*- coding:utf-8 -*-
'''
Created on 2009-12-28

@author: squall
'''
'''
解析第一次获得的网页的内容
'''
import re
import urllib
class parse:
    def __init__(self,wangzhi):
        m=re.compile(r'(?<=</colgroup...).+?(?=</script)',re.I|re.S)
        s=[]
        num=[]
        self.netnum=[]
        self.songname=[]
        f=urllib.urlopen(wangzhi)
        data=f.read()
        s=m.findall(data)
        wl=s[0]
        wl=wl.replace('\n\nWL','')
        wl=wl.replace('\t\n<script>','')
        wl=wl.replace('"','')  
        s=wl.split(';')
        x=[]
        for i in range(len(s)):
            x=s[i].split(',')
            if len(x)>=3:
                num.append(x[0])
                self.netnum.append(x[1])
                self.songname.append(x[2])
        for i in range(len(num)):
            num[i]=num[i].replace('(','')
            self.netnum[i]=self.netnum[i].replace(' ','')
            self.songname[i]=self.songname[i]
            self.netnum[i]='http://www.songtaste.com/song/'+self.netnum[i]+'/'
    def getSongName(self):
        return self.songname
    def getSongNet(self):
        return self.netnum
if __name__=="__main__":
    p=parse("http://www.songtaste.com/user/album/a205654#")
    song=p.getSongName()
    print len(song)
    for i in range(len(song)):
        print song[i].decode('gb18030','replace')
